package com.bst.datax.executor.service.jobhandler.streamload;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * ID 按哈希值分片两类分片方式
 */
public class DataShardingStrategy {
    public static List<Map<String, Object>> shardData(List<Map<String, Object>> fullData, int shardCount) {
        int batchSize = (int) Math.ceil((double) fullData.size() / shardCount);
        return null; // Lists.partition(fullData, batchSize);
    }

    // 按ID范围分片（适合大表）
    public static List<String> createIdRangeShards(String idColumn, long minId, long maxId, int shardCount) {
        long step = (maxId - minId) / shardCount;
        List<String> shards = new ArrayList<>();

        for (int i = 0; i < shardCount; i++) {
            long start = minId + i * step;
            long end = (i == shardCount - 1) ? maxId : start + step - 1;
            shards.add(idColumn + " BETWEEN " + start + " AND " + end);
        }

        return shards;
    }

//    public static List<Map<String, Object>> partition(List<Map<String, Object>> list, int size) {
//        return IntStream.range(0, (list.size() + size - 1) / size)
//                .mapToObj(i -> list.subList(
//                        i * size,
//                        Math.min((i + 1) * size, list.size())))
//                .collect(Collectors.toList());
//    }
}
